package com.example.administrator.u17.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/11/16.
 */

public class ShouCangAdapter<T> extends BaseAdapter{
    private Context context;
    private List<T> list;

    public ShouCangAdapter(Context context, List<T> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ShouCangViewHolder holder;
        if (convertView==null){
            convertView=View.inflate(context,R.layout.item_shoucang,null);
            holder=new ShouCangViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder=(ShouCangViewHolder)convertView.getTag();
        }
//        T t = list.get(position);
//        holder.tvName.setText(t);
//        holder.tvAuthor.setText(t);
//        Picasso.with(context).load(t).into(holder.iv);
        return convertView;
    }

    class ShouCangViewHolder{
        ImageView iv;
        TextView tvName,tvAuthor;
        public ShouCangViewHolder(View view){
            iv=(ImageView)view.findViewById(R.id.iv_item_shoucang);
            tvName=(TextView)view.findViewById(R.id.tv_item_shoucang_name);
            tvAuthor=(TextView)view.findViewById(R.id.tv_item_shoucang_author);
        }
    }
}
